						<?php
						require_once "db/db.php";
						?>
						<form action = "" method = "post">
						<table>
							<tr>
								<th>Email: </th>
								<td class = "input"><input type = "text" name = "email"/></td>
							</tr>
							<tr>
								<th>Mật khẩu: </th>
								<td class = "input"><input type = "password" name = "pass"/></td>
							</tr>	
							<tr>
								<td></td>
								<td>Nhớ <input type = "checkbox" name = "remember"/> | 
									<a href = "fpass.php">Quên mật khẩu?</a>
									
									</td>
							</tr>				
							<tr>
								<td></td>
								<td class = "button"><input type = "submit" name = "submit" value = "Đăng nhập"/></td>
							</tr>
						</table>												
					</form>
					<?php						
					//call function singin webpage
					Singin();
					?>
					
					<!--Form login with google, yahoo...-->
					<div class = "title">Đăng nhập với tài khoản khác</div>
					<table>
						<tr>
							<td>
								<a href = "login-openid.php?pg=g">
									<img src = "images/google.png"/></a>   
							</td>
							<th>:Với tài khoản google </th>
							
						</tr>
						<tr>
							<td>
								<a href = "login-openid.php?pg=y">
									<img src = "images/yahoo.png"/></a>
					
							</td>
							<th>:Với tài khoản yahoo </th>	
							
						</tr>
						<tr>
							<th><a href = "login-openid.php">Xem thêm</a></th>
							<td></td>
						</tr>
						
					</table>					
					

<?php
function Singin()
	{
		if(isset($_POST['submit']))
			{
				$email = $_POST['email'];
				$pass = $_POST['pass'];
				
				if($email && $pass)
					{
						$pass = sha1 ($pass);
										
						$login = DbLogin($email, $pass);
						
						if($login)
							{
								//construct session in new one active
								foreach($login as $values)
									{
										$_SESSION['user_id'] = $values['id'];
										$_SESSION['full_name'] = $values['fullName'];
										
										//image defaulf 
										if($values['image'] == "")
											{
												//is femail
												if($values['gender'] == 0)
													$_SESSION['image'] = "IB7NOFmPw2a.gif";
												//is mail
												else
													$_SESSION['image'] = "UlIqmHJn-SK.gif";
											}
										//image user uploaded	
										else
											$_SESSION['image'] = $values['image'];	
									}
								//check checkbox user need save cookie	
								 if(isset($_POST['remember']))
							         {
							            setcookie("email", $email, time() + 60*60*100, "/");
							            setcookie("pass", $pass, time() + 60*60*100, "/");
							           
							         }
							         
							     echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";										
									
							}
						else
							echo "<p class = 'error'>Đăng nhập thất bại.</p>";	
					}
				else 
					echo "<p class = 'error'>Nhập đầy đủ thông tin.</p>";	
				
			}
			
	}
?>	
